
import { LOGIN_TOKEN } from '@/constants'
import { localCache } from '@/utils/cache'
import { BASE_URL, BASE_URL_AUTH, TIME_OUT } from './config'
import GstyRequest from './request'
export const gstyRequest = new GstyRequest({
    baseURL: BASE_URL,
    timeout: TIME_OUT,
    interceptors: {
        requestSuccessFn: (config) => {
            const token = localCache.getCache('login/token/base')
            if (config.headers) {
                config.headers.Authorization = `Bearer ${token}`
            }
            return config
        }
    },
})
export const gstyRequestAuth = new GstyRequest({
    baseURL: BASE_URL_AUTH,
    timeout: TIME_OUT,
    interceptors: {
        requestSuccessFn: (config) => {
            const token = localCache.getCache(LOGIN_TOKEN)
            if (config.headers && token) {
                config.headers.Authorization = `Bearer ${token}`
                config.headers['Content-Type'] = 'application/json;charset=UTF-8'
            }
            return config
        }
    },

})
export const gstyRequestToken = new GstyRequest({
    baseURL: BASE_URL_AUTH,
    timeout: TIME_OUT,
    interceptors: {
        requestSuccessFn: (config) => {
            let client_id = 'fuswyb3wdoicgl91theyobwz'
            let client_secret = '254lldagqycsn70njek0zdja4aq4khqn'
            if (config.headers) {
                // config.headers.Authorization = ' Basic base64(${' + client_id + '}:${' + client_secret + '})'
                config.headers.Authorization = `Basic ZnVzd3liM3dkb2ljZ2w5MXRoZXlvYnd6OjI1NGxsZGFncXljc243MG5qZWswemRqYTRhcTRraHFu`
                config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
            }

            return config
        }
    },

})
